package org.micro.rbac.core.exception;


import lombok.Getter;
import lombok.Setter;
import org.micro.rbac.core.result.Code;

import java.io.Serial;

/**
 * 授权异常
 *
 * @author hongsir
 * @since 2021-03-09 11:45:39
 */
@Getter
@Setter
public class GrantException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 6610083281801529147L;

    public GrantException(String message) {
        super(message);
    }

    public GrantException(String message, Throwable throwable) {
        super(message, throwable);
    }

    public GrantException(Throwable throwable) {
        super(throwable);
    }


    private String code;
    private String message;

    public GrantException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }


    public static GrantException newError(String code, String message) {
        return new GrantException(code, message);
    }

    public static GrantException newError(String message) {
        return newError(Code.FAIL.code(), message);
    }

    public static GrantException newError() {
        return newError(Code.FAIL.message());
    }

}
